/*
 * webpack相关
 * @author li.xiaomei
 * @date 2016-12-19
 */

var webpack = require('webpack')
var path = require('path')


//会把编译后的静态文件全部保存在内存中, 而不会写入到文件目录内
//运行于内存中的文件系统
exports.dev = function(config, compiler){
  return require(path.resolve(__dirname, '../../node_modules','webpack-dev-middleware'))(compiler, {
      publicPath: config.output.publicPath,
      stats: {
        colors: true,
        chunks: false
      }
    })
}

exports.hot = function(config, compiler){
  //结合 webpack-dev-middleware 使用的middleware, 它可以实现浏览器的无刷新更新
  //var hotMiddleware = require(path.resolve(__dirname, '../../node_modules','webpack-hot-middleware'))(compiler)
  // force page reload when html-webpack-plugin template changes
  // compiler.plugin('compilation', function (compilation) {
  //   compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) {
  //     hotMiddleware.publish({ action: 'reload' })
  //     cb()
  //   })
  // })
  var hotMiddleware = require(path.resolve(__dirname, '../../node_modules','webpack-hot-middleware'))(compiler, {
    log: console.log, path: '/__webpack_hmr', heartbeat: 10 * 1000
  })
  return hotMiddleware;
}
